package demo01;

import java.util.Scanner;

//二维前缀和
public class Solution {
    public int[][] arr = {{0,0,0,0},{0,1,2,3},{0,2,3,4},{0,1,2,3}};
    public int sumFunction(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入X1,y1,x2,y2: ");
        int x1 = scanner.nextInt();
        int y1 = scanner.nextInt();
        int x2 = scanner.nextInt();
        int y2 = scanner.nextInt();
        int[][] dp = new int[4][4];
        //处理dp表
        for (int i = 1; i <=3 ; i++) {
            for (int j = 1; j <=3 ; j++) {
                dp[i][j] = dp[i-1][j] + dp[i][j-1]-dp[i-1][j-1] + arr[i][j];
            }
        }
        //使用dp表
        int num = dp[x2][y2] - dp[x1-1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1];
        return num;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.sumFunction());
    }
}
